#include "bits/stdc++.h"
#define int long long
using namespace std;
int x,y; 
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>x>>y;
        cout<<y/(x+1)*2+(y%(x+1)? (y%(x+1)>1? 2:1):0)-(x==0&&y)<<'\n';
    }
}
